using FytSoa.ApiService.Filters;
using FytSoa.ApiService.Swagger;
using FytSoa.Application;
using FytSoa.Common.Extensions;
using FytSoa.Common.Utils;
using FytSoa.CrossCutting;
using FytSoa.Quartz.Extensions;
using Microsoft.Extensions.FileProviders;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
AppConfigUtils.InitConfig (builder.Configuration);

builder.Services.AddControllers(options =>
{
    options.Filters.Add<AopActionFilter>();
    options.Filters.Add<GlobalExceptionFilter>();
    options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true;
}).AddJsonOptions(options =>
{
    options.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
    options.JsonSerializerOptions.Converters.Add(new LongJsonConverter());
});

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerConfiguration();

// Register DI
builder.Services.RegisterServices();

// Mapper
builder.Services.AddMapperProfile();



var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwaggerSetup();
}

//app.UseHttpsRedirection();

app.UseAuthorization();

//app.UseQuartz();
app.UseCors (c => {
    c.AllowAnyHeader ();
    c.AllowAnyMethod ();
    c.AllowAnyOrigin ();
    c.WithExposedHeaders ("RefreshToken");
});

app.UseStaticFiles (new StaticFileOptions {
    ServeUnknownFileTypes = true,
    FileProvider = new PhysicalFileProvider (Directory.GetCurrentDirectory ())
});

app.MapControllers();

app.Run();